﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlaughterItem.API.Application.Commands.Week02.Killplan;
using SlaughterItem.API.Application.Commands.Week02.Setups;
using SlaughterItem.API.Controllers.SuYi;
using SlaughterItem.Common.Dtos;

namespace SlaughterItem.API.Controllers.WangHaoQi
{
    /// <summary>
    /// 批宰计划新增
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SlaughtersController : ControllerBase
    {

        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<Week2SetupController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public SlaughtersController(IMediator mediator, ILogger<Week2SetupController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 批宰计划添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddSlaughter(SlaughterCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("批宰计划添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("批宰计划添加失败" + ex.Message);

                throw;
            }
        }
    }
}
